
  -- Lightroom SDK
local LrHttp = import 'LrHttp'
local LrPathUtils = import 'LrPathUtils'
local LrFileUtils = import 'LrFileUtils'
local logger = import 'LrLogger'( 'RhubarbHttpClient' )

local LrErrors = import 'LrErrors'

RhubarbHttpClient = {}

RhubarbHttpClient.uploadImage = function(server, authToken, album_name, album_pass, imagePath, timeoutSeconds)

	local filename = LrPathUtils.leafName( imagePath )
	
	local content = 
		{ 
			{ name='albumName', value=album_name },
			{ name='albumPass', value=album_pass },
			{ name='authToken', value=authToken },
			{ name = 'uploadedImage',
				  fileName = filename,
				  filePath = imagePath,
				  contentType = 'multipart/form-data'
		    }
		}	

	local url = server .. '/upload.php'
	
	local response, headers = LrHttp.postMultipart( url, content, timeoutSeconds )
	
	local httpStatus = headers.status;
	if httpStatus == 403 then
		LrErrors.throwUserError( 'Authentication failed. Please verify your Secret in the export settings. You find it in config/secret.php on your server inside the single quotes.' )
	end
	
end
